﻿using System.Linq;
using InfoSite.SiteMembership.Interface;
using InfoSite.SiteMembership.Provider;
using InfoSite.Tools;

namespace InfoSite.SiteMembership.Service
{
	public class AccountRoleService : IRoleService
	{
		private readonly SiteRoleProvider _provider;

		public AccountRoleService()
			: this(null)
		{
		}

		public AccountRoleService(SiteRoleProvider provider)
		{
			_provider = provider ?? new SiteRoleProvider();
		}

		public bool AdminExists()
		{
			return _provider.GetUsersInRole(EnumHelper.RequiredRoles.Admin.ToString()).Count() != 0;
		}

		public bool RoleExists(string roleName)
		{
			return _provider.RoleExists(roleName);
		}

		public bool IsUserInRole(string email, string roleName)
		{
			return _provider.IsUserInRole(email, roleName);
		}

		public string[] GetUsersInRole(string roleName)
		{
			return _provider.GetUsersInRole(roleName);
		}

		public void AddUsersToRoles(string[] usernames, string[] rolenames)
		{
			_provider.AddUsersToRoles(usernames, rolenames);
		}

		public void RemoveUsersFromRoles(string[] usernames, string[] rolenames)
		{
			_provider.RemoveUsersFromRoles(usernames, rolenames);
		}

		public void CreateRole(string roleName, string roleDescription)
		{
			_provider.CreateRole(roleName, roleDescription);
		}
	}
}
